package com.janyee.buddha.view

import android.graphics.Paint
import android.graphics.Typeface
import com.janyee.buddha.MyApplication

/**
 * Created by kmlixh on 17/11/28.
 * useage:
 * TextTest
 */
open interface Painter {
    fun getNormalTextPaint(): Paint
    fun getChoosedTextPaint(): Paint
    fun getChoosedBackPaint(): Paint
    fun getLineHeight():Float
    fun getSingleWordWidth(): Float
}
open class TextPainter:Painter{
    override fun getSingleWordWidth(): Float {
        return normalPaint.measureText("测")
    }

    override fun getLineHeight(): Float {
        return normalPaint.fontMetrics.descent-normalPaint.fontMetrics.ascent
    }

    var normalPaint:Paint
    var choosedBack:Paint
    var choosedText:Paint
    constructor( fontSize:Float, normalTextColor: Int, choosedTextColor: Int, backgroundColor: Int){
        val typeface = Typeface.createFromAsset(MyApplication.Instance().assets, "SourceHanSans-Light.ttc")
//        val typeface=Typeface.createFromAsset(MyApplication.Instance().assets,"SourceHanSansCN-Normal.otf")
        normalPaint = Paint(Paint.ANTI_ALIAS_FLAG)
        normalPaint.color=normalTextColor
        normalPaint.textSize=fontSize
        normalPaint.typeface = typeface
        normalPaint.textAlign=Paint.Align.LEFT
        choosedBack = Paint(Paint.ANTI_ALIAS_FLAG)
        choosedBack.color=backgroundColor
        choosedBack.textSize=fontSize
        choosedText = Paint(Paint.ANTI_ALIAS_FLAG)
        choosedText.textSize=fontSize
        choosedText.color=choosedTextColor
        choosedText.typeface = typeface
        choosedText.textAlign=Paint.Align.LEFT

    }
    override fun getChoosedTextPaint(): Paint {
        return choosedText
    }

    override fun getChoosedBackPaint(): Paint {
        return choosedBack
    }

    override fun getNormalTextPaint(): Paint {
       return normalPaint
    }
    fun setTextSize(size:Float){
        normalPaint.textSize=size
        choosedText.textSize=size
    }
    fun setNormalColor(color: Int){
        normalPaint.color=color
    }
    fun setChoosedTextColor(color:Int){
        choosedText.color=color
    }
    fun setChoosedBackColor(color:Int){
        choosedBack.color=color
    }
    fun setTypeface(typeface: Typeface){
        normalPaint.setTypeface(typeface)
        choosedText.setTypeface(typeface)
    }

}